package com.xywl.escort.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.MultipleItemRvAdapter;
import com.xywl.escort.adapter.provider.BannerItemProvider;
import com.xywl.escort.adapter.provider.NoticeItemProvider;
import com.xywl.escort.adapter.provider.RecycleGridItemProvider;
import com.xywl.escort.adapter.provider.RecycleItemProvider;
import com.xywl.escort.adapter.provider.TextImgItemProvider;
import com.xywl.escort.bean.BannerResp;
import com.xywl.escort.bean.MarketDataBean;
import com.xywl.escort.bean.MessageResp;
import com.xywl.escort.bean.NoticeResp;
import com.xywl.escort.bean.ProjectListResp;
import com.xywl.escort.entity.NormalMultipleEntity;

import java.util.List;

public class HomeRvAdapter extends MultipleItemRvAdapter<NormalMultipleEntity, BaseViewHolder> {

    public static final int TYPE_BANNER = 100;
    public static final int TYPE_NOTICE = 200;
    public static final int TYPE_TEXT_IMG = 300;
    public static final int TYPE_RECYCLE = 400;
    public static final int TYPE_RECYCLE_GRID = 500;
    private List<NormalMultipleEntity> mData;

    public HomeRvAdapter(@Nullable List<NormalMultipleEntity> data) {
        super(data);

        this.mData = data;
        finishInitialize();
    }

    @Override
    protected int getViewType(NormalMultipleEntity entity) {
        if (entity.type == NormalMultipleEntity.BANNER) {
            return TYPE_BANNER;
        } else if (entity.type == NormalMultipleEntity.NOTICE) {
            return TYPE_NOTICE;
        } else if (entity.type == NormalMultipleEntity.TEXT_IMG) {
            return TYPE_TEXT_IMG;
        } else if (entity.type == NormalMultipleEntity.RECYCLE) {
            return TYPE_RECYCLE;
        } else if (entity.type == NormalMultipleEntity.RECYCLE_GRID) {
            return TYPE_RECYCLE_GRID;
        }
        return 0;
    }

    @Override
    public void registerItemProvider() {
        mProviderDelegate.registerProvider(new BannerItemProvider());
        mProviderDelegate.registerProvider(new NoticeItemProvider());
        mProviderDelegate.registerProvider(new TextImgItemProvider());
        mProviderDelegate.registerProvider(new RecycleItemProvider());
        mProviderDelegate.registerProvider(new RecycleGridItemProvider());
    }

    public void setBannerList(List<BannerResp.DataBean> data) {
        mData.get(0).mBannerData = data;
        notifyDataSetChanged();
    }

    public void setNoticeList(List<NoticeResp.DataBean.ListBean> data) {
        mData.get(1).noticeData = data;
        notifyDataSetChanged();
    }

    public void setProjectList(List<ProjectListResp.DataBean.ListBean> data) {
        mData.get(6).mProjectData = data;
        notifyDataSetChanged();
    }

    public void setMarketList(List<MarketDataBean> data) {
        mData.get(7).marketData = data;
        notifyDataSetChanged();
    }
}
